import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import vueJsx from '@vitejs/plugin-vue-jsx'
import { resolve } from 'path'

const mockApiUrl = 'https://console-mock.apipost.cn/app/mock/project/79ea3b05-05f2-4f42-b40d-3d7f56281f27' // mock接口
const devApiUrl = 'http://api-dev.scrm.keyid.cn' // 开发环境接口

export default ({ mode, command }) =>
  defineConfig({
    plugins: [vue(), vueJsx()],
    server: {
      host: '0.0.0.0',
      port: 8080,
      open: true,
      proxy: {
        '/zw-api': {
          target: mode === 'mock' ? mockApiUrl : devApiUrl,
          changeOrigin: true,
          rewrite: (path) => path.replace(/^\/zw-api/, '')
        }
      }
    },
    resolve: {
      alias: {
        '@': resolve(__dirname, './src'),
        '~': resolve(__dirname, './src')
      }
    },
    build: {
      minify: 'terser',
      terserOptions: {
        compress: {
          drop_console: command === 'build' && mode === 'prod',
          drop_debugger: command === 'build' && mode === 'prod'
        }
      }
    }
    // css: {
    //   preprocessorOptions: {
    //     scss: {
    //       additionalData: `@use "~/styles/element/index.scss" as *;`,
    //     },
    //   },
    // },
  })
